package osTest;

import os.MiniMutex;


public class MiniMutexTest
{
	public static void main(String[] args)
	{	
		final MiniMutex mutex = new MiniMutex(1);
		Runnable r = new Runnable()
		{
			@Override
			public void run()
			{
				mutex.P();
				try
				{
					System.out.println("Thread no "+Thread.currentThread().getId()+" entered critical section");
					Thread.sleep(100);
					System.out.println("Thread no "+Thread.currentThread().getId()+" leaved critical section");
				}
				catch (InterruptedException e)
				{
					e.printStackTrace();
				}
				mutex.V();
			}
		};
		
		Runnable r2 = new Runnable()
		{
			@Override
			public void run()
			{
				mutex.V();
			}
		};

		for(int i = 0; i < 10; i++)
		{
			Thread t = new Thread(r);
			t.start();
//			try
//			{
//				Thread.sleep(300);
//			}
//			catch (InterruptedException e)
//			{
//				e.printStackTrace();
//			}
		}
		
//		Thread t2 = new Thread(r2);
//		t2.start();
	}
}
